<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <?php
        //一、接收表单fore数据并处理：注意：POST提交方式数据是以关联数组的形式存储在$_POST全局数组里
        echo "hello denglu<br>";
        var_dump($_POST);
        echo "<br>";
        $username=$_POST['uname'];
        $password=$_POST['upwd'];
        echo "$username,$password<br>";
         //二、处理表单数据，操作数据表并返回结果，操作数据表（插入、查询、删除、更新）
        //1.连接数据库
        $link=  mysqli_connect("localhost","root");//创建一个数据库
        mysqli_select_db($link,"nhcar");//选择所查询的数据库
        mysqli_set_charset($link,"utf8");//设置字符集
        //2.写SQL语句，首先写SQL模板
        $sql="SELECT*FROM users WHERE uname='$username' AND upwd='$password'";
        echo "$sql<br>";
         //3.执行查询返回结果，查询select，成功返回结果集，失败返回false，插入insert，更新update 删除delete，成功返回true，失败false
         $result=  mysqli_query($link, $sql);
         var_dump($result);
         
//         exit();
         $row=  mysqli_fetch_row($result);//返回一组数组数据
         //三处理返回结果
         if($row){
             //header 页面跳转
//             header("Location:index.php");
            echo "<script>alert('登陆成功！');location.href='index.php'</script>";
         }  else {
//             header("Location:register.php");
            echo "<script>alert('登陆失败，请前往注册！');location.href='register.php'</script>";
         }
        ?>
    </body>
</html>